home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dviapollo / interact.c < prev    next >
C/C++ Source or Header  |  1990-10-01  |  3KB  |  149 lines

  1. #include "genwindow.h"
  2. #define NULL 0
  3. int curpage; /* The page currently displayed. */
  4. static int downx = 0; /* The X,Y coordinates when a button last went */
  5.               /* down. */ 
  6. static int downy = 0;
  7. static int xscreen = 0;
  8. static int yscreen = 0;
  9. static DVIW dviw = NULL; /* The DVI window to display. */
  10. char *curfilename ();
  11. enum buttontype {quit, load, bottom, top, next, previous};
  12. struct buttonrec {char *name; int width; int x; int y;
  13.           enum buttontype callout; };
  14. static struct buttonrec buttons [] =
  15. {{"Quit",     4, 31, 0, quit},
  16.  {"Load",     4, 31, 1, load},
  17.  {"Bottom",   8, 37, 0, bottom},
  18.  {"Top",      8, 47, 0, top},
  19.  {"Next",     8, 37, 1, next},
  20.  {"Previous", 8, 47, 1, previous},
  21.  {0}};
  22.  
  23. void redisplay ()
  24. {
  25.   if (dviw) {
  26.     curpage = ShowDviPage (&dviw, curpage, xscreen, yscreen);
  27.     show_slider (dviw -> pages);
  28.     update_slider (curpage);
  29.   } else {
  30.     clearscreen ();
  31.     show_slider (1);
  32.   }
  33. }
  34.  
  35. /* Reset page offset.  This does NOT refresh the screen, so the caller */
  36.  /* should do it.*/ 
  37. void reset_scroll ()
  38. {
  39.   xscreen = -RESOLUTION;
  40.   yscreen = -RESOLUTION;
  41. }
  42.  
  43. void load_proc ()
  44. {
  45.   reset_scroll ();
  46.   dviw = ReOpenDvi (dviw, curfilename ());
  47.   curpage = 1;
  48.   redisplay ();
  49. }
  50.  
  51. void next_proc ()
  52. {
  53.   reset_scroll ();
  54.   curpage++;
  55.   redisplay ();  
  56. }
  57.  
  58. void previous_proc ()
  59. {
  60.   reset_scroll ();
  61.   curpage --;
  62.   redisplay ();  
  63. }
  64.  
  65. void refresh_proc ()
  66. {
  67.   redisplay ();
  68. }     
  69.  
  70. void top_proc ()
  71. {
  72.   reset_scroll ();
  73.   redisplay ();
  74. }
  75.  
  76. void bottom_proc ()
  77. {
  78.   xscreen = -RESOLUTION;
  79.   /* The number 10 is below because pages are 8.5 x 11, and there is a */
  80.   /* one inch margin between the top and the (0,0) dvi coordinate. */
  81.   yscreen = (10 * RESOLUTION) - screen_height ();
  82.   redisplay ();
  83. }
  84.  
  85. void quit_proc ()
  86. {
  87.   exit (0);
  88. }
  89.  
  90. void buttondown (x, y)
  91. {
  92.   downx = x;
  93.   downy = y;
  94. }
  95.  
  96. void buttonup (x, y)
  97. {
  98.   xscreen += downx - x;
  99.   yscreen += downy - y;
  100.   redisplay ();
  101. }
  102.  
  103. /* This routine calls create_a_button once for each record in */
  104.  /* buttonrec.  This allows us to only say once where each button is */
  105.  /* for both the sunview and the X implementations. */
  106. void create_buttons ()
  107. {
  108.   struct buttonrec *thisbutton;
  109.   void (* callout) ();
  110.   
  111.   thisbutton = buttons;
  112.   while (thisbutton -> name) {
  113.     switch (thisbutton -> callout) {
  114.     case quit:
  115.       callout = quit_proc; break;
  116.     case load:
  117.       callout = load_proc; break;
  118.     case bottom:
  119.       callout = bottom_proc; break;
  120.     case top:
  121.       callout = top_proc; break;
  122.     case next:
  123.       callout = next_proc; break;
  124.     case previous:
  125.       callout = previous_proc; break;
  126.     default:
  127.       fprintf (stderr, "Lost miserably while creating buttons.\n");
  128.       exit (1);
  129.       break;
  130.     }
  131.     create_a_button (thisbutton -> name,
  132.              thisbutton -> width,
  133.              thisbutton -> x,
  134.              thisbutton -> y, callout);
  135.     thisbutton ++;
  136.   };
  137.   return;
  138. }
  139.  
  140. /* This routine should be called to move to page pagenum.*/
  141. void goto_page (pagenum)
  142.    int pagenum;
  143. {
  144.   reset_scroll ();
  145.   curpage = pagenum;
  146.   redisplay ();
  147. }
  148.  
  149.